package com.mwx.baselib.view;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mwx.baselib.R;
import com.mwx.baselib.utils.StickFullScreen;


/**
 * Created by Administrator on 2017/5/23 0023.
 */

public class LoadingDialog {
    private final TextView loadingText;
    LVCircularRing mLoadingView;
    Dialog mLoadingDialog;
    private static LoadingDialog loadingDialog;
    public static LoadingDialog getLoading(Context context){
        if (loadingDialog==null){
            loadingDialog = new LoadingDialog(context);
        }
        return  loadingDialog;
    }
    public LoadingDialog(Context context) {
        // 首先得到整个View
        View view = LayoutInflater.from(context).inflate(
                R.layout.loading_dialog_view, null);
        // 获取整个布局
        LinearLayout layout = (LinearLayout) view.findViewById(R.id.dialog_view);
        // 页面中的LoadingView
        mLoadingView = (LVCircularRing) view.findViewById(R.id.lv_circularring);
        // 页面中显示文本
         loadingText = (TextView) view.findViewById(R.id.loading_text);
        // 创建自定义样式的Dialog
        mLoadingDialog = new Dialog(context, R.style.loading_dialog);
        // 设置返回键无效
       mLoadingDialog.setCancelable(false);
        mLoadingDialog.setContentView(layout, new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));
    }

    public void show(){
        if (!mLoadingDialog.isShowing()){
            mLoadingDialog.show();
            mLoadingView.startAnim();
        }

    }
    public void show(String msg){
        loadingText.setText(msg);
        show();

    }

    public void close(){
        if (mLoadingDialog!=null) {
            mLoadingView.stopAnim();
            mLoadingDialog.dismiss();
            loadingDialog=null;
//            mLoadingDialog=null;
        }
    }
}
